﻿using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using System;
using System.Collections.Generic;
using System.Text;

namespace BCMongoEntity
{
    /// <summary>
    /// 芒果数据库基础实体信息
    /// </summary>
    public class MongoDBBaseEntity
    {
        [BsonId]
        private ObjectId _id;
        public string Id {
            get {
                if (string.IsNullOrWhiteSpace(_id.ToString()))
                    return ObjectId.GenerateNewId().ToString();
                else
                    return _id.ToString();
            }
            set {
                if (string.IsNullOrWhiteSpace(value))
                    _id = ObjectId.GenerateNewId();
                else
                    _id = new ObjectId(value);
            }
        }

        /// <summary>
        /// kafka临时消息Id
        /// </summary>
        [BsonElement("TemplateMessageId")]
        public string TemplateMessageId { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [BsonElement("CreateTime")]
        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        public DateTime CreateTime { get; set; }
        /// <summary>
        /// 修改时间
        /// </summary>
        [BsonElement("UpdateTime")]
        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        public DateTime UpdateTime { get; set; }
    }
}
